<!--
 * @Author: 陈俊升 761723995@qq.com
 * @Date: 2023-05-11 08:47:22
 * @LastEditors: 陈俊升 761723995@qq.com
 * @LastEditTime: 2024-01-31 14:10:38
 * @FilePath: /hr_new_vue3/src/views/Management/Human/HumanRoster/FileDetail/Components/Container/ChangeRecord/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 人员档案详情-异动记录-人员异动 -->
<template>
  <div>
    <TableTurn :tableData="getTableData" ref="tableRef">
      <a-table-column :width="80">
        <template #title> 序号 </template>
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="异动类型" data-index="">
        <template #cell="{ record }">
          {{ typeList.find((el: any) => el.id == record.type)?.name }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="异动原因" data-index="">
        <template #cell="{ record }">
          {{
            data?.transactionTypeList?.find((el: any) => el.id == record.reason)
              ?.reason
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="部门" data-index="">
        <template #cell="{ record }">
          {{
            data?.organizationList?.find((el: any) =>
              el.id == record.department
                ? record.department
                : data?.personDetail?.['CED44AC9966904CD1AB546D309903727C']
            )?.name || '---'
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="职位" data-index="">
        <template #cell="{ record }">
          {{
            data?.positionList?.find((el: any) =>
              el.id == record.position
                ? record.position
                : data?.personDetail?.['C7341027925C943708F3AEF98703ECC47']
            )?.name || '---'
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="职务" data-index="">
        <template #cell="{ record }">
          {{
            data?.jobList?.find((el: any) =>
              el.id == record.duties
                ? record.duties
                : data?.personDetail?.['C1F5AA49A78EC4B4FBD487F4D5887E576']
            )?.name || '---'
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="职级" data-index="">
        <template #cell="{ record }">
          {{
            record.levelRange ||
            data?.personDetail?.['C5B3625070EFD4698A20925CE32B31F16'] ||
            '---'
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="汇报上级" data-index="">
        <template #cell="{ record }">
          {{
            data?.humanRosterList?.find((el: any) =>
              el.id == record.up
                ? record.up
                : data?.personDetail?.['CECEBAA743F9B4160B40A5A3E78588712']
            )?.name || '---'
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="工作地点" data-index="">
        <template #cell="{ record }">
          {{
            data?.workplaceList?.find((el: any) =>
              el.id == record.place
                ? record.place
                : data?.personDetail?.['CE009C2E2B542409D815F0D3D54FE0E2B']
            )?.name || '---'
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="合同公司" data-index="">
        <template #cell="{ record }">
          {{
            data?.lawList?.find((el: any) =>
              el.id == record.contractCompany
                ? record.contractCompany
                : data?.personDetail?.['C8258F2F3F7EC4D9C803A291BB7BFEE28']
            )?.name || '---'
          }}
        </template>
      </a-table-column>
      <a-table-column :width="100" title="生效日期" data-index="effectTime">
      </a-table-column>
      <a-table-column
        :width="100"
        title="办理人"
        data-index=""
      ></a-table-column>
      <a-table-column
        :width="100"
        title="办理时间"
        data-index="applicationTime"
      ></a-table-column>
      <a-table-column :width="100" title="异动状态" data-index="">
        <template #cell="{ record }">
          {{ record.isDone === 1 ? '已生效' : '进行中' }}
        </template>
      </a-table-column>
      <a-table-column :width="150" fixed="right" title="操作">
        <template #cell="{ record }">
          <a-tooltip content="查看详情">
            <icon-font
              type="icon-details-def"
              :size="26"
              :style="{
                cursor: 'pointer',
                marginRight: '10px'
              }"
              @click="goDetail(record)"
            />
          </a-tooltip>
        </template>
      </a-table-column>
    </TableTurn>
  </div>
</template>

<script lang="ts" setup>
import { GetTransactionDetailList } from '@/apis/management/personnel/changeManagement/transactionManagement';
import { PERSONNEL_CHANGE, TRANSACTION } from '@/utils/constants';
import { getAllHumanChangeSettingType } from '@/utils/common';
import { Idata } from '@/utils/getAllSwitchListData';

const props = withDefaults(
  defineProps<{
    data: Idata; // 数据
  }>(),
  {}
);

const route = useRoute();
const router = useRouter();

let id = Number(route.query.id);

let typeList = ref([]); //异动类型列表

const getData = async () => {
  try {
    typeList.value = await getAllHumanChangeSettingType();
  } catch (error: unknown) {
    console.log(error);
  }
};
getData();
const getTableData = async (pageData?: any) => {
  try {
    const res = await GetTransactionDetailList({
      ...pageData,
      id
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};

const goDetail = (data: any) => {
  router.push({
    name: 'TransactionRecordDetail',
    params: { id: data.id }
  });
};
</script>

<style lang="less" scoped>
.wrap {
  padding: 10px 20px;
  display: flex;
}
</style>
